use std::{error::Error, io};

fn main() {
    println!("Hello, world!");
    let url = "https://www.baidu.com/";
    http_get_main(url).unwrap();
}

fn http_get_main(url:&str) ->Result<(), Box<dyn Error>> {
    let mut resp = reqwest::blocking::get(url)?;

    if !resp.status().is_success() {
        return Err(format!("error: {}", resp.status()))?;
    }

    // println!("resp = {:?}", resp);
    // println!("resp.status() = {:?}", resp.status());
    // println!("resp.headers() = {:?}", resp.headers());
    // println!("resp.text() = {:?}", resp.text()?);

    let stdout = io::stdout();
    io::copy(&mut resp, &mut stdout.lock())?;
    println!("");
    Ok(())
}
